package backpage.mapper;

import backpage.entity.SalarySummary;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;

@Mapper
public interface SalarySummaryMapper {

    /**
     * 插入员工工资汇总信息
     * @param employeeId 员工 ID
     * @param month 月份
     * @param hourPay 小时工资
     * @param totalPay 总工资
     * @param overtimePay 加班工资
     * @param compoffPay 调休扣款
     * @return 插入成功的记录数
     */
    @Insert("INSERT INTO salary_summary (employee_id, month, hour_pay, total_salary, overtime_pay, compoff_pay) " +
            "VALUES (#{employeeId}, #{month}, #{hourPay}, #{totalPay}, #{overtimePay}, #{compoffPay})")
    int insertSalarySummary(Long employeeId, Date month, Double hourPay, Double totalPay, Double overtimePay, Double compoffPay);


    @Update("UPDATE salary_summary " +
            "SET employee_id = #{employeeId}, " +
            "month = #{month}, " +
            "hour_pay = #{hourPay}, " +
            "total_salary = #{totalSalary}, " +
            "overtime_pay = #{overtimePay}, " +
            "compoff_pay = #{compoffPay} " +
            "WHERE id = #{id}")
    void update(SalarySummary salarySummary);

    @Select("SELECT * FROM salary_summary WHERE employee_id = #{employeeId} AND month = #{month}")
    SalarySummary selectByEmployeeIdAndMonth(Long employeeId, Date month);
}